<?php

declare(strict_types=1);

namespace App\CustHub\Controller;

use App\CustHub\Annotation\ApiAuth;
use App\CustHub\Annotation\VerifySignature;
use App\CustHub\Request\RoomBroadcastRequest;
use App\CustHub\Service\ChRoomBroadcastService;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: 'ch/room/broadcast'),ApiAuth,VerifySignature]
class RoomBroadcastController extends BaseController
{
    #[Inject]
    protected ChRoomBroadcastService $service;

    #[PostMapping('list')]
    public function list()
    {
        return $this->success($this->service->list($this->request->all()));
    }

    /**
     * 添加
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('save')]
    public function save(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->save($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 详情
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('getInfo')]
    public function getInfo(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->getInfo($request->input('id')));
    }

    /**
     * 修改
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('update')]
    public function update(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->update($request->input('id'),$request->all()) ? $this->success() : $this->error();
    }

    /**
     * 复制
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('copy')]
    public function copy(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->copy($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 重命名
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('rename')]
    public function rename(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->rename($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 修改状态
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('changeStatus')]
    public function changeStatus(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->changeStatus($request->input('id'),$request->input('status')) ? $this->success() : $this->error();
    }

    /**
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('delete')]
    public function delete(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        $ids = json_decode($request->input('id'),true);
        return $this->service->delete($ids) ? $this->success() : $this->error();
    }

    /**
     * 转播记录
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('records')]
    public function records(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->records($request->all()));
    }

    /**
     * 目标群发送记录
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('targets')]
    public function targets(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->success($this->service->targets($request->all()));
    }

    /**
     * 撤回消息
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('recallMessage')]
    public function recallMessage(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->recallMessage($request->all()) ? $this->success() : $this->error();
    }

    /**
     * 重新发送
     * @param RoomBroadcastRequest $request
     * @return \Psr\Http\Message\ResponseInterface
     * @throws \Psr\Container\ContainerExceptionInterface
     * @throws \Psr\Container\NotFoundExceptionInterface
     */
    #[PostMapping('resend')]
    public function resend(RoomBroadcastRequest $request): \Psr\Http\Message\ResponseInterface
    {
        return $this->service->resend($request->all()) ? $this->success() : $this->error();
    }
}